// 引入内置模块http
const http = require("http");
const fs = require("fs");

// 创建http服务器
const server = http.createServer((req, res) => {
  fs.readFile(__dirname + "/4-index.html", "utf-8", (err, data) => {
    if (err) {
      res.setHeader("Content-Type", "text/plain");
      res.statusCode = 404;
      res.end("Not Founded");
    } else {
      res.setHeader("Content-Type", "text/html");
      res.statusCode = 200;
      res.end(data);
    }
  });
});
// ip
const hostname = "127.0.0.1";
// 端口号
const port = 3000;
server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
